package com.anrongtec.zcpt.manager;

import java.util.ArrayList;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.base.BaseActivity;
import com.anrongtec.zcpt.module.Statistical;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.adapter.recyclerview.wrapper.EmptyWrapper;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;


/**
 * 我的统计
 * @author cxy
 *
 */
public class MyStatisticalActivity extends BaseActivity {

	private RecyclerView recyclerView;
	private CommonAdapter<Statistical> adapter;
	
	private ArrayList<Statistical> statisticals;
	
	private EmptyWrapper<Statistical> empty;
	
	private static final int EMPTY = 1;
	private static final int REFRESH = 2;
	private Handler h = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case EMPTY:
				empty.setEmptyView(R.layout.empty_view);
				recyclerView.setAdapter(empty);
				break;
			case REFRESH:
				empty.notifyDataSetChanged();
				break;

			default:
				break;
			}
		}
	};
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitleShow(true);
		setContentView(R.layout.activity_my_statistical);
		
		initViews();
		
	}

	@Override
	protected void onCreateCustomToolBar(Toolbar toolbar) {
		toolbar.setTitle("我的统计");
	}
	
	@Override
	protected void initViews() {
		initRecyclerView();
	}
	
	private void initRecyclerView(){
		
		statisticals = new ArrayList<Statistical>();
		statisticals.add(new Statistical("警信", 20, 5));
		statisticals.add(new Statistical("情报指令", 7, 3));
		statisticals.add(new Statistical("公安新闻", 5, 7));
		
		
		recyclerView = (RecyclerView) findViewById(R.id.rv_statistical);
		recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
		adapter = new CommonAdapter<Statistical>(this, R.layout.item_statistical, statisticals) {
			@Override
			protected void convert(ViewHolder holder, Statistical t, int position) {
				holder.setText(R.id.tv_statistical_name, t.getName());
				holder.setText(R.id.tv_statistical_count, t.getCount()+"");
				holder.setText(R.id.tv_statistical_ranking, t.getRanking()+"");
			}
		};
		
//		HeaderAndFooterWrapper<Statistical> header = new HeaderAndFooterWrapper<Statistical>(adapter);
//		header.addHeaderView(LayoutInflater.from(this).inflate(R.layout.item_statistical_head, null));
		
		empty = new EmptyWrapper<Statistical>(adapter);
		empty.setEmptyView(R.layout.loading_view);
		
		recyclerView.setAdapter(empty);
	}
	
	
}
